$(function() {
		var initPagination = function() {
			num_entries = $("#hiddenresult div.result").length;
			// 创建分页
			page = 10; //!!!!!!每页个数！！！！！！
			$("#Pagination").pagination(num_entries, {
				num_edge_entries : 2, //边缘页数
				num_display_entries : 6, //主体页数
				callback : pageselectCallback,
				items_per_page : page, //每页显示1项
				prev_text : "前一页",
				next_text : "后一页"
			});
		}();

		function pageselectCallback(page_index, jq) {
			var max_elem = Math.min((page_index + 1) * page, num_entries);
			$("#Searchresult").empty();
			for ( var i = page_index * page; i < max_elem; i++) {
				$("#Searchresult").append(
						$("#hiddenresult div.result:eq(" + i + ")").clone());
			}
			return false;
		}
		
		$(".favorite").click(function(){
			var aID=$(this).attr("id");
			var articleObject=$(this);
			if($(this).attr("src")=="images/selected.png"){
				$.ajax({
					type: "POST",
					url: "http://localhost:803/EasyAjax/jQueryAjaxTest.ashx",  
					data: "articleID="+aID+"&operation=delete",
					beforeSend: function(){
						alert("数据处理中...");
					},
					success: function(msg){
						alert(msg);
						articleObject.attr("src","images/unselected.png");
						articleObject.attr("alt","我关注");
					},
					error: function(xhr, type, exception) {
                		alert("对不起，出错了！");
   				    }
				});
			}
			else{

				$.ajax({
						type: "POST",
						url: "http://localhost:803/EasyAjax/jQueryAjaxTest.ashx",  
						data: "articleID="+aID+"&operation=addfocus",
						beforeSend: function(){
							alert("数据处理中...");
						},
						success: function(msg){
							alert(msg);
							articleObject.attr("src","images/selected.png");
							articleObject.attr("alt","取消\"关注\"");
						},
						error: function(xhr, type, exception) {
           					alert("对不起，出错了！");
        				}
				});
			}
		});
	});